package RemoteServerTest;

import java.rmi.RemoteException;
import java.util.ArrayList;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import Po.BookPO;
import Po.Discount;
import Po.IdCustomer;
import Po.Manager;
import Po.ManagerCustomer;
import Po.Message;
import Po.Order;
import Po.Promotion;
import Po.Result;
import Po.State;
import RemoteServer.SaleManagerServer;
import RemoteServerInterface.SaleManagerServerInterface;

public class SaleManagerServerTest {

	SaleManagerServerInterface test;
	@Before
	public void setUp() throws Exception {
		test=new SaleManagerServer();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testGetCustomer() throws RemoteException {
		ManagerCustomer m = test.getCustomer(1);
		Assert.assertTrue(m.ID == 1);
	}
	@Test
	public final void testGetAllCustomer() throws RemoteException {
		ArrayList<IdCustomer> list = test.getAllCustomer();
		Assert.assertTrue(list.size() == 4);
		Assert.assertTrue(list.get(0).ID == 1);
	}
	@Test
	public final void testDetail() throws RemoteException {
		Assert.assertTrue(test.getBookDetail("1").iSBN.equals("1"));
	}
	
	@Test
	public final void testAddBook() throws RemoteException {
		Message m = test.addBook(new BookPO("qw", "qw", "qw", 0.00, "qw", "qw", 0));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testModifyBook() throws RemoteException {
		test.addBook(new BookPO("qw", "qw", "qw", 0.00, "qw", "qw", 0));
		Message m = test.modifyBook(new BookPO("qw", "qw", "qw", 0.00, "qw", "qw", 34));
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testDelBook() throws RemoteException {
		Message m = test.deleteBook("qw");
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testAddNode() throws RemoteException {
		Message m = test.addNode("a", "b");
		Assert.assertTrue(m.result == Result.Success);
	}
	
	
	@Test
	public final void testModifyNode() throws RemoteException {
		test.addNode("a", "b");
		Message m = test.modifyNode("a", "c");
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testDelNode() throws RemoteException {
		Message m = test.deleteNode("a");
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testPresent() throws RemoteException {
		Message m  = test.presentPromotion(new Discount(null, null, null, null, 1, 0), 1, 1);
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testGet() throws RemoteException {
		ArrayList<Promotion> list = test.getAllPromotionList();
		Assert.assertTrue(list.size() == 4);
		Assert.assertTrue(list.get(0).ID == 1);
	}
	
	@Test
	public final void testSmLogin() throws RemoteException {
		Manager m = test.SaleManagerLogin(new Manager("zjq", "111111"));
		Assert.assertTrue(m.name.equals("zjq"));
		Assert.assertTrue(m.password.equals("111111"));
	}
	@Test
	public final void testModify() throws RemoteException {
		Message m = test.modifyOrder(2, State.order);
		Assert.assertTrue(m.result == Result.Success);
	}
	
	@Test
	public final void testGetAll() throws RemoteException {
		ArrayList<Order> list = test.getUnfinishedOrderList();
		Assert.assertTrue(list.size() == 3);
		Assert.assertTrue(list.get(0).state == State.order);	
	}



}
